/*商品分类*/
$(function () {
    $('.all-sort-list2 > .item').hover(function () {
        //父类分类列表容器的高度

        $(this).addClass('hover');
        $(this).children('.item-list').css('display', 'block');
    }, function () {
        $(this).removeClass('hover');
        $(this).children('.item-list').css('display', 'none');
    });

    $('.item > .item-list > .close').click(function () {
        $(this).parent().parent().removeClass('hover');
        $(this).parent().hide();
    });
});

function queding() {
    var text = document.querySelector(".yemian");
    var username = document.querySelector(".username");
    window.location.href = "http://172.18.210.18:18086/p?page=" + text.value + "&&size=20&&username=" + username.innerHTML;
}

$(document).ready(function () {
    if ($("#btn").text('取消收藏')) {
        $("#btn").text('收藏');
    } else {
        $("#btn").text('取消收藏');
    }
})

function addsc(username, id) {
    $.ajax({
        type: "POST",
        url: "/goods/addsc",
        data: {"username": username, "id": id},
        dataType: "json",
        success: function (data) {
            if (data.code) {
                $("#btn").text('取消收藏');
            } else {
                $("#btn").text('收藏');
            }
        }
    })
}

function deleltesc(id) {
    $.ajax({
        type: "POST",
        url: "/goods/deletesc",
        data: {"username": username, "id": id},
        dataType: "json",
        success: function (data) {
            if (data.code) {
                $("#btn").text('收藏');
            } else {
                $("#btn").text('取消收藏');
            }
        }
    })
}


$("#btn").click(function () {
    var username = document.querySelector(".username").textContent;
    var id = document.querySelector(".shoucang").textContent;
    if ($("#btn").text('收藏')) {
        addsc(username, id);
        $("#btn").text('取消收藏');
    } else {
        deleltesc(id);
        $("#btn").text('收藏');
    }

})

